
export const getTreeItemById = (list, id, children) => {
  let childCode = children ? children : 'children'
  for (let i = 0; i < list.length; i++) {
    if (list[i].id === id) {
      return list[i]
    } else if (list[i][childCode] && list[i][childCode].length > 0) {
      let res = getTreeItemById(list[i][childCode], id)
      if (res) {
        return res
      }
    }
  }

  return null
}


// 根据id属性从数组（树结构）中移除元素
export const removeTreeItemById = (treeList, id) => {
  if (!treeList || !treeList.length) {
    return
  }
  for (let i = 0; i < treeList.length; i++) {
    if (treeList[i].id === id) {
      treeList.splice(i, 1);
      break;
    }
    removeTreeItemById(treeList[i].children, id)
  }
}
